<?php

namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Models\Post;

class UserController extends Controller {

    public function __construct() {
        $this->middleware('need_user_login')->except('index');
    }

    public function user($id) {
        $user = User::findOrFail($id);
        if(request()->app_user == $user){
            $posts = $user->get_posts();
        }else{
            $posts = $user->get_posts(Post::PUBLIC_STATUS);
        }
        return view('app.user.user', ['user' => $user, 'posts' => $posts]);
    }
}

